package com.linan.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Utils {
    public static  String encrypByMd5(String context)  {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
            md.update(context.getBytes());
            byte[] encrypContext = md.digest();
            int i ;
            StringBuffer buf = new StringBuffer();
            for (int offest = 0; offest < encrypContext.length; offest++) {
                i = encrypContext[offest];
                if(i<0){
                    i += 256;
                }
                if(i<16){
                    buf.append("0");
                }
                buf.append(Integer.toHexString(i));
            }
            return buf.toString();
        } catch (NoSuchAlgorithmException e) {
            System.out.println(e);
            return null;
        }


    }
}
